package main;

import java.io.IOException;
import java.util.LinkedList;
import java.util.Scanner;

import plochki.BaiGosho;
import plochki.BaiGrozdan;
import plochki.BaiPesho;
import plochki.BaiPetkan;
import plochki.BaiTupan;
import plochki.BaseWorker;
import tests.TestMivki;


public class ProjectStart {
		public static void main(String[] args) throws IOException {
			
			//Get the console input in the form of lines of figures
			String[] figures = getConsoleInputFigures();
			
			maistorskaRabota(figures);
		}
		
		private static String[] getConsoleInputFigures() {
			Scanner reader;
			reader = new Scanner(System.in);

			int n = Integer.parseInt(reader.nextLine());
			
			String[] lines = new String[n];
			
			for (int i = 0; i < n; i++) {
				lines[i] = reader.nextLine();
			}
			
			reader.close();
			
			return lines;
		}

		private static void maistorskaRabota(String[] figures) throws IOException {
			
			LinkedList<BaseWorker> workers = new LinkedList<BaseWorker>();
			
			//Make the work in the easy way
			workers.add(new BaseWorker(figures));
			//Make the work in the easy way, traverse the figures in reverse order
			workers.add(new BaiPesho(figures));
			//Make the work in the easy way, traverse the figures (with even then odd indexes)
			workers.add(new BaiGosho(figures));
			//A more complicated approach, uses Collision Cells
			workers.add(new BaiGrozdan(figures));
			//A more complicated approach, Collisions traversed in a reversed order
			workers.add(new BaiPetkan(figures));
			//A more complicated approach, Collisions traversed first even indexes then odd indexes
			workers.add(new BaiTupan(figures));
			
			//Each worker to make his work
			for(BaseWorker worker: workers) {
				worker.deistvai();
			}
			
			BaseWorker fastestWorker = TestMivki.findFastestWorker(workers);
			
			//System.err.println("Tests finished. Best worker: " + fastestWorker.name
			//		+ " Moves: " + fastestWorker.movesMade);
			
			System.out.print(fastestWorker.getFinalResult());
		}

}
